package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EventDetails;
import com.ruoyi.system.service.IEventDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事件详细信息Controller
 *
 * @author ruoyi
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/system/details")
public class EventDetailsController extends BaseController
{
    @Autowired
    private IEventDetailsService eventDetailsService;

    /**
     * 查询事件详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(EventDetails eventDetails)
    {
        startPage();
        List<EventDetails> list = eventDetailsService.selectEventDetailsList(eventDetails);
        return getDataTable(list);
    }

    /**
     * 导出事件详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:details:export')")
    @Log(title = "事件详细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EventDetails eventDetails)
    {
        List<EventDetails> list = eventDetailsService.selectEventDetailsList(eventDetails);
        ExcelUtil<EventDetails> util = new ExcelUtil<EventDetails>(EventDetails.class);
        util.exportExcel(response, list, "事件详细信息数据");
    }

    /**
     * 获取事件详细信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:details:query')")
    @GetMapping(value = "/{eventId}")
    public AjaxResult getInfo(@PathVariable("eventId") Long eventId)
    {
        return success(eventDetailsService.selectEventDetailsByEventId(eventId));
    }

    /**
     * 新增事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:details:add')")
    @Log(title = "事件详细信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EventDetails eventDetails)
    {
        return toAjax(eventDetailsService.insertEventDetails(eventDetails));
    }

    /**
     * 修改事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:details:edit')")
    @Log(title = "事件详细信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EventDetails eventDetails)
    {
        return toAjax(eventDetailsService.updateEventDetails(eventDetails));
    }

    /**
     * 删除事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:details:remove')")
    @Log(title = "事件详细信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{eventIds}")
    public AjaxResult remove(@PathVariable Long[] eventIds)
    {
        return toAjax(eventDetailsService.deleteEventDetailsByEventIds(eventIds));
    }
}
